// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import App from './App'
import router from './router'
import store from './store'
import './assets/js/rem'
import {Progress} from 'element-ui'
import {Switch} from 'element-ui'
import {Input} from 'element-ui'
import {Dialog} from 'element-ui'
import {Select} from 'element-ui'
import {Option} from 'element-ui'
import {List} from 'vant'
import {PullRefresh} from 'vant'
import 'vant/lib/index.css'
import 'element-ui/lib/theme-chalk/index.css'  //单独引入样式文件

import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)
Vue.use(Progress)
Vue.use(Switch)
Vue.use(Input)
Vue.use(Dialog)
Vue.use(Select)
Vue.use(Option)
Vue.use(List)
Vue.use(PullRefresh)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})

Vue.prototype.routerTo = function (path) {
  this.$router.push({path: path})
}

/***
 * 弹框提示
 * */
Vue.prototype.Toast = function (msg, duration) {
  if (document.getElementById('new_Toast')) {
    return false
  }
  duration = isNaN(duration) ? 3000 : duration
  let m = document.createElement('div')
  m.id = 'new_Toast'
  let defaultCss = `
     -webkit-transition: all 600ms ease;
     -webkit-transform:translate(0,0rem);
     min-width: 4.5rem;
     padding:0 0.2rem 0 0.2rem;
     opacity: 0;
     color: rgb(255, 255, 255, 1);
     text-align: center;
     border-radius: 0.06rem;
     position: fixed;
     bottom: 15%;
     left: 50%;
     margin-left: -2.25rem;
     z-index: 999999;
     display: flex;
     align-items: center;
     justify-content: center;
     height: 0.9rem;
     background: rgba(248, 98, 98, 0.9);
     font-size: 0.333rem;
     border-radius: 2.5rem;
  `
  let showCss = `
     -webkit-transition: all 600ms ease;
     -webkit-transform:translate(0,-0.75rem);
     min-width: 4.5rem;
     padding:0 0.2rem 0 0.2rem;
     opacity: 0.8;
     color: rgb(255, 255, 255, 1);
     text-align: center;
     border-radius: 0.06rem;
     position: fixed;
     bottom: 15%;
     left: 50%;
     margin-left: -2.25rem;
     z-index: 999999;
     display: flex;
     align-items: center;
     justify-content: center;
     height: 0.9rem;
     background: rgba(248, 98, 98, 0.9);
     font-size: 0.333rem;
     border-radius: 2.5rem
  `
  m.style.cssText = defaultCss
  m.innerHTML = msg
  setTimeout(function () {
    m.style.cssText = showCss
  }, 0)
  document.body.appendChild(m)
  setTimeout(function () {
    let d = 0.5
    m.style.cssText = defaultCss
    setTimeout(function () {
      document.body.removeChild(m)
    }, d * 1000)
  }, duration + 600)
}

/***
 * 把时间戳转换成时间
 * */
Vue.prototype.dateTransform = (time, format) => {
  if (isNaN(time)) return ''

  let date = new Date(time * 1000)
  format = format || 'yyyy/MM/dd hh:mm'
  let o = {
    'M+': date.getMonth() + 1, // 月份
    'd+': date.getDate(), // 日
    'h+': date.getHours(), // 小时
    'm+': date.getMinutes(), // 分
    's+': date.getSeconds(), // 秒
    'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
    'S': date.getMilliseconds() // 毫秒
  }
  if (/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (let k in o) {
    if (new RegExp('(' + k + ')').test(format)) {
      format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
  }
  return format
}

/***
 * 限制数组保留几位小数
 * */
Vue.prototype.toFixed = (number, n) => {
  let num = number + ''
  let dotIndex = num.indexOf('.')
  if (dotIndex > -1) {
    num = num.substring(0, dotIndex + n + 1)
  }
  return +num
}

Vue.prototype.isiOS = () => {
  let u = navigator.userAgent
  return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) //ios终端\
}
